using Framework;
using UnityEngine;
using UnityEngine.AI;
public class Player : Npc
{
    private Fsm _fsm;

    protected override void OnAwake()
    {
        base.OnAwake();
        _fsm = new Fsm();
        _fsm.Owner = this;
        var idle = _fsm.Add("Idle");
        idle.AddAction(new NpcIdle());
        idle.AddTransition("Walk");
        idle.AddTransition("Action");
        var walk = _fsm.Add("Walk");
        walk.AddAction(new NpcMove());
        walk.AddTransition("Idle");
        var action = _fsm.Add("Action");
        action.AddAction(new NpcAct());
        var wait = new NpcWait();
        wait.Time = 0.1f;
        action.AddAction(wait);
        action.AddTransition("Idle", Fsm.EventActionFinish);
        _fsm.Start("Idle");
    }
    protected override void OnUpdate(float deltaTime, float unscaledDeltaTime)
    {
        base.OnUpdate(deltaTime, unscaledDeltaTime);
        if (_fsm != null)
        {
            _fsm.Update(deltaTime);
        }
    }
    public void Move(Vector3 dir, float deltaTime)
    {
        if (this._agent == null) return;
        if (dir.sqrMagnitude < 0.01f) return;
        _fsm.SendEvent("Walk");
        this.MoveDirection = dir;
        if (!Moving)
        {
            Moving = true;
        }
    }
    public void Action()
    {
        _fsm.SendEvent("Action");
    }
    protected override void onMoveEnd()
    {
        base.onMoveEnd();
        _fsm.SendEvent("Idle");
    }
}